package t327.util;

import com.baidu.aip.face.AipFace;
import com.baidu.aip.face.MatchRequest;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

public class BaiDuFaceUntil {


    private  static  AipFace aipFace;

    static{
        aipFace= new AipFace(
                "34061840","Dg0USd0Y8pAtwTp9dkDL0aQt","ekGUqUoDDbO8vWRAgrOS5gh8Zkf5cQf8");



    }
/**
 * @Author 10202
 * @Description 描述
 * @Date 2023/5/29 14:35
 * @param image1 图片一
 * @param image2
 *
 * @return void
 **/
public static JSONObject faceCompare(String image1,String image2) {


    // image1/image2也可以为url或facetoken, 相应的imageType参数需要与之对应。
    MatchRequest req1 = new MatchRequest(image1, "BASE64");
    MatchRequest req2 = new MatchRequest(image2, "BASE64");
    ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
    requests.add(req1);
    requests.add(req2);

    return  aipFace.match(requests);


}


public static JSONObject addPhone(String img,String userId) {
    // 传入可选参数调用接口
    HashMap<String, String> options = new HashMap<String, String>();
    options.put("user_info", "学生照片");
    options.put("quality_control", "NORMAL");
    options.put("liveness_control", "LOW");
    options.put("action_type", "REPLACE");

    String image =img;
    String imageType = "BASE64";
    String groupId = "327";


    // 人脸注册
    return aipFace.addUser(image, imageType, groupId, userId, options);


}

public JSONObject signIn(String img, String userId) {
    HashMap<String, String> options = new HashMap<String, String>();
    options.put("match_threshold", "80");
    options.put("quality_control", "NORMAL");
    options.put("liveness_control", "LOW");
    options.put("user_id", userId);
    options.put("max_user_num", "1");
    String image =img;
    String imageType = "BASE64";
    String groupIdList = "327";

    // 人脸搜索
    JSONObject res = aipFace.search(image, imageType, groupIdList, options);
    return  res;

}


}
